package com.zy.project1.aspects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @program: mavenTest153
 * @description:
 * @author: zy
 * @create: 2025-07-16 09:39
 */
@Aspect   //这是一个切面类
@Component
@Order(value=0)
public class MyAspect2 {

    ////  对所有的操作记录操作时长.
    //1.要用环绕增强
    @Pointcut("execution(* com.zy.project1.biz.*.*(..))")
    public void all(){}

    @Around("all()")

    public Object doTime(   ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("***********开始执行计时....**************");
        long start=System.currentTimeMillis();  //开始时间
        Object retVal=pjp.proceed();  //执行目标方法
        long end=System.currentTimeMillis();   //结束时间
        System.out.println("===================");
        System.out.println("操作耗时:"+(end-start));
        System.out.println("===================");
        return retVal;
    }


}
